<!DOCTYPE html>
<html>

<head>

	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">


	<title>{$Think.config.site.title} - 订单管理</title>

	<meta name="keywords" content="{$Think.config.site.keywords}">

	<link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
	<link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
	<link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
	<link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">

</head>
<style>
	#listtable .fa {
		cursor: pointer;
		color: #1ab394;
		margin-right: 1em;
	}

	#listtable .fa.bg-w {
		color: #fff
	}

	th .tag {
		font-size: 12px;
		color: #e66c6c;
		font-weight: normal;
	}

	.ibox-title .tag {
		font-size: 12px;
		color: #e66c6c;
		font-weight: normal;
		display: inline-block;
		margin-left: 20px;
	}

	.specval-hide {
		display: none;
	}

	.btn-group {
		font-size: 0
	}

	.btn-group .btn {
		margin-left: -1px
	}

	.btn-group .btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
		border-radius: 0
	}

	.btn-group>.btn:first-child:not(:last-child):not(.dropdown-toggle) {
		border-bottom-right-radius: 0;
		border-top-right-radius: 0
	}

	.btn-group>.btn:last-child:not(:first-child),
	.btn-group>.dropdown-toggle:not(:first-child) {
		border-bottom-left-radius: 0;
		border-top-left-radius: 0
	}

	.table tbody {
		border-top: 2px solid #999 !important;
	}

	.change_box {
		margin: 20px;
	}

	.commit {
		margin: 20px 0;
	}
	.btn-active{
		position: relative;
		top:-5px;
		box-shadow: 0 7px 5px #888888;
	}
	.btn-group .btn{
		color: white;
	}
	.all_order{
		background-color: rgb(28, 179, 148);
	}
	.wating_order{
		background-color: rgb(237, 86, 103);		
	}
	.reserve_order{
		background-color: rgb(247, 171, 89);
	}
	.wating_save_order{
		background-color: rgb(29, 132, 198);
	}
	.btn-wating{
		background-color: rgb(84, 171, 53);
	}
	.btn-canceled {
		background-color: rgb(194, 194, 194);
	}
	.btn-finish{
		background-color: rgb(149, 149, 149);
	}
</style>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div id="nestable-menu" class="btn-group">
					<a href="{:url('index',array('order_status' => 1000))}"><span class="{if condition='$status eq 1000'}btn-active{/if} all_order btn btn-w-m">全部订单</span></a>
					<a href="{:url('index',array('order_status' => 20))}"><span class="{if condition='$status eq 20'}btn-active{/if} btn-danger btn btn-w-m">待接单</span></a>
					<a href="{:url('index',array('order_status' => 25))}"><span class="{if condition='$status eq 25'}btn-active{/if} btn-warning btn btn-w-m">待补价</span></a>
					<a href="{:url('index',array('order_status' => 30))}"><span class="{if condition='$status eq 30'}btn-active{/if} btn-success btn btn-w-m">待发货</span></a>
					<a href="{:url('index',array('order_status' => 40))}"><span class="{if condition='$status eq 40'}btn-active{/if} btn-wating btn btn-w-m">待收货</span></a>
					<!-- <a href="{:url('index',array('order_status' => 50))}"><span class="{if condition='$status eq 50'}btn-primary{else/}btn-default{/if} btn btn-w-m">退货中</span></a> -->
					<a href="{:url('index',array('order_status' => 10))}"><span class="{if condition='$status eq 10'}btn-active{/if} btn-canceled btn btn-w-m">已取消</span></a>
					<a href="{:url('index',array('order_status' => 100))}"><span class="{if condition='$status eq 100'}btn-active{/if} btn-finish btn btn-w-m">已完成</span></a>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>订单列表</h5>
					</div>
					<div class="ibox-content">
						<div class="row">
							<div class="col-sm-6">
								<button type="button" data-action="addnew" class="btn btn-primary btn-sm openall">展开 / 收起</button>
								<a href="javascript://" class="btn btn-primary btn-sm excel">导出Excel</a>
								<!-- {eq name="status" value="1000"}
									<span class="btn btn-danger m-l"></span> 待接单
									<span class="btn btn-warning m-l"></span> 待补价
									<span class="btn btn-success m-l"></span> 待发货
									<span class="btn btn-primary m-l"></span> 待收货
								{/eq} -->
							</div>
							<div class="col-sm-6">
								<div class="input-group pull-right">
									<form action="{:url('index')}" method="get" enctype="application/x-www-form-urlencoded">
										<div class="input-group">
											<input type="hidden" name="order_status" value="{$status}" />
											<input type="text" placeholder="请输入关键字" class="input-sm form-control" name="keywords">
											<input type="hidden" class="pay_time" name="pay_time" value="">
											<span class="input-group-btn">
		                                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button> 
											</span>
										</div>
									</form>
								</div>
							</div>

						</div>
						<div class="table-responsive">
							<table class="table" id="listtable">
								<thead>
									<tr>
										<th><input name="checkall" id="checkall" type="checkbox" class="i-checks" value="1"></th>
										<th width="30"></th>
										<th>订单号</th>
										<th>买家信息</th>
										<th class="pay_time_sort" data-pay_time_sort='{$sort}'>订单时间 {if condition='$sort eq "pay_time desc"'}<span>&darr;</span>{else /}<span>&uarr;</span>{/if}</th>
										<th>商品总价</th>
										<th>订单总价</th>
										<th>改价金额</th>
										<th>订单备注</th>
										<th>订单状态</th>
										<th>操作</th>
									</tr>
								</thead>
								{volist name="list" id="vo"}
								<tbody>
									<tr class="goodsname" data-id="{$vo.order_id}" style="background: #f1f1f1;">
										<td><input name="ids[]" type="checkbox" class="i-checks" value="{$vo.order_id}"></td>
										{eq name="status" value="1000"}
											{switch name="$vo['order_status']"}
												{case value="20"}<td class="btn-danger"></td>{/case}
												{case value="25"}<td class="btn-warning"></td>{/case}
												{case value="30"}<td class="btn-success"></td>{/case}
												{case value="40"}<td class="btn-wating"></td>{/case}
												{case value="10"}<td class="btn-canceled"></td>{/case}
												{case value="100"}<td class="btn-finish"></td>{/case}
											{/switch}
										{else/}
											<td></td>			
										{/eq}
										<td>&nbsp;{$vo.order_no}</td>
										<td>{$vo.receiver_name} {$vo.receiver_mobile}
											<p style="margin: 0; max-width: 280px;">{$vo.receiver_pcd}{$vo.receiver_address}</p>
										</td>
										<td>
											下单时间：{$vo.create_time}<br >
											支付时间：{$vo.pay_time}<br >
											{if($vo['shipping_time'])}配送时间：{$vo.shipping_time}<br >{/if}
											{if($vo['delivery_name'])}配 送 员 ：{$vo.delivery_name}{/if}
										</td>
										<td>商品总价：{$vo.goods_money}<br />运费：{$vo.shipping_money}</td>
										<td>订单总价：{$vo.order_money}<br />支付金额：{$vo.pay_money}</td>
										<td>{$vo.refund_money_total}</td>
										<td><p style="margin: 0; max-width: 280px;">{$vo.remarks}</p></td>
										<td>
											{switch name="$vo['order_status']"} 
												{case value="20"}已支付{/case} 
												{case value="30"}备货中{/case} 
												{case value="40"}待收货{/case} 
												{case value="100"}已完成{/case} 
											{/switch}
										</td>
										<td class="action">
											{switch name="$vo['order_status']"} 
											{case value="20"}
												<button data-order_id="{$vo.order_id}" data-order_status="30" class="btn btn-primary jiedan"><i class="fa fa-edit bg-w"></i>接单</button>
												<a data-order_id="{$vo.order_id}" class="fa fa-edit refund"> 退货</a>
												<a data-order_id="{$vo.order_id}" class="fa fa-edit change_price">改价</a>
												<a data-order_id="{$vo.order_id}" data-order_status="10" class="fa fa-edit cancel"> 取消</a>
												<button type="button" class="btn btn-primary btn-sm details"> 详情</button>
											{/case} 
											{case value="30"}
												<button data-action="shipping" data-href='{:url("shipping/index",' ',false)}' type="button" class="btn btn-primary btn-sm shipping"> 发货</button>
												<a data-order_id="{$vo.order_id}" class="fa fa-edit refund"> 退货</a>
												<a data-order_id="{$vo.order_id}" class="fa fa-edit change_price">改价</a>
												<a data-order_id="{$vo.order_id}" data-order_status="10" class="fa fa-edit cancel"> 取消</a>
												<button type="button" class="btn btn-primary btn-sm details"> 详情</button>
											{/case} 
											{case value="40"} 
												{gt name=":strtotime($vo.shipping_time)+604800" value=":time()"}
													<!-- <a data-order_id="{$vo.order_id}" class="fa fa-edit refund"> 退货</a> -->
												{else/}
													<a data-order_id="{$vo.order_id}" data-order_status="100" type="button" class="btn btn-primary btn-sm receipt"> 确认收货</a>											
												{/gt}
												<a data-order_id="{$vo.order_id}" class="fa fa-edit refund"> 退货</a>
												<a data-order_id="{$vo.order_id}" class="fa fa-edit change_price">改价</a>
												<a data-order_id="{$vo.order_id}" data-order_status="10" class="fa fa-edit cancel"> 取消</a>
												<button type="button" class="btn btn-primary btn-sm details"> 详情</button>
											{/case} 
											{default /}
												<a data-order_id="{$vo.order_id}" class="fa fa-edit refund"> 退货</a>
												<button type="button" class="btn btn-primary btn-sm details"> 详情</button>
											{/switch}
											<button type="button" class="btn btn-primary btn-sm printcode">打印条码</button>
										</td>
									</tr>
									{volist name="vo['goods']" id="voo"}
									<tr data-id="{$voo.goods_id}" data-specval_id="{$voo.goods_specval_id}" class="tr-specval specval-{$vo.order_id}">
										<td></td>
										<td></td>
										<td><img src="{$voo.goods_picture}" alt="" width="30" height="30" /></td>
										<td colspan="2">{if condition="$voo.brand_name!=''"}（{$voo.brand_name}）{/if}{$voo.goods_name}【{$voo.goods_specval_name}】 x{$voo.num}</td>
										<td colspan="2">单价: {$voo.price}</td>
										<td colspan="10">数量: {$voo.num}</td>
									</tr>
									{/volist}
								</tbody>
								{/volist}
							</table>
						</div>
						<div>{$list->render()}</div>
					</div>
				</div>
			</div>
		</div>
		<table class="hidden copy_excel">
			<thead>
				<tr>
					<th></th>
					<th width="30"></th>
					<th>订单号</th>
					<th>买家信息</th>
					<th class="pay_time_sort" data-pay_time_sort='{$sort}'>订单时间 {if condition='$sort eq "pay_time desc"'}<span>&darr;</span>{else /}<span>&uarr;</span>{/if}</th>
					<th>商品总价</th>
					<th>订单总价</th>
					<th>改价金额</th>
					<th>订单备注</th>
					<th>订单状态</th>
					<th>操作</th>
				</tr>
			</thead>
		</table>
		<audio id="audio" class="hidden" src="{$Think.config.site.resource_url}audio/kiss.mp3" />
	</div>

	<script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
	<script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
	<script src="{$Think.config.site.resource_url}js/plugins/peity/jquery.peity.min.js"></script>
	<script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
	<script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
	<script src="{$Think.config.site.common_resource_url}js/majax.js"></script>
	<script src="{$Think.config.site.common_resource_url}js/jedit.js"></script>
	<script src="{$Think.config.site.resource_url}js/tableExporter.min.js"></script>
</body>
<script type="text/html" id="change_box">
	<div class="change_box">
		<div class="input-group">
			<span class="input-group-addon">改变价格：</span>
			<input type="number" step="0.01" class="form-control" id="shop_price" placeholder="请输入改动价格">
		</div>
		<div class="input-group">
			<span class="input-group-addon">备注信息：</span>
			<textarea type="text" class="form-control" id="remarks" placeholder="请输入备注信息"></textarea>
		</div>
		<div class "clearfix">
			<button class="btn btn-primary pull-right commit">提交</button>
		</div>
	</div>
</script>

</html>
<script>
	//切换排序
	$('.pay_time_sort').click(function(){
	    var pay_time_sort = $(this).data('pay_time_sort');
	    if(pay_time_sort == "pay_time desc"){
	        $('.pay_time').val("pay_time asc");
	    }else{
	        $('.pay_time').val("pay_time desc");
	    }
	    $('form').submit();
	})

	$('.goodsname td:not(".action")').click(function () {
		var id = $(this).closest('tr').data('id');
		$('.specval-' + id).toggleClass('specval-hide');
	})

	$('.openall').click(function () {
		$('.tr-specval').toggleClass('specval-hide');
	})

	$(document).on('click', '.jiedan', function () {
		$(this).removeClass('jiedan');
		$(this).removeClass('btn-primary');
		$(this).text('已接单');
		var order_id = $(this).data('order_id');
		var order_status = $(this).data('order_status');
		$this = $(this);
		majax('{:url("index")}', { order_id: order_id, order_status: order_status }, function (msg) {
		// $this.closest('tbody').remove();
	});
	});

	$('.shipping').click(function () {
		console.log($(this).data("href"))
		top.window.redirectTab($(this).data("href"));
	})

	$(document).on('click', '.cancel', function () {
		var order_id = $(this).data('order_id');
		var order_status = $(this).data('order_status');

		layer.confirm('订单取消将提交财务审核', {
            btn: ['确定','取消'], //按钮
            shade: false //不显示遮罩
        }, function(){
            //确定取消
            majax('{:url("cancel")}', { order_id: order_id, order_status: order_status }, function (re) {
            	if (re.code<=0) {
            		layer.msg(re.msg,{icon:5})
            	}
            });
        },
        function(){
            
        });

		
	});

	$(document).on('click', '.receipt', function () {
		var order_id = $(this).data('order_id');
		var order_status = $(this).data('order_status');
		majax('{:url("receipt")}', { order_id: order_id, order_status: order_status }, function (msg) {
		});
	});

	var layer_font = '';
	$(document).on('click', '.refund', function () {
		var order_id = $(this).data('order_id');
		layer_font = layer.open({
			type: 2,
			title: '退货',
			shadeClose: true,
			shade: 0.8,
			area: ['50%', '90%'],
			content: '{:url("refund")}?order_id=' + order_id //iframe的url
		});
	});

	$(document).on('click','.details',function(){
		var $tr = $(this).closest("tr");
		var order_id = $tr.data('id');
		layer_font = layer.open({
		  type: 2,
		  title: '订单详情',
		  shadeClose: true,
		  shade: 0.8,
		  area: ['900px', '90%'],
		  content: '{:url("details")}?order_id='+order_id, //iframe的url
		});
	});

	$(document).ready(function () {
			
		$(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });

		//全选
		$("#checkall").bind("ifChecked", function () {
			$("input[name='ids[]']").iCheck("check");
		});
		//取消全选
		$("#checkall").bind("ifUnchecked", function () {
			$("input[name='ids[]']").iCheck("uncheck");
		});
		//导航按钮
		$("#nestable-menu span").on("click", function (e) {
			// $(this).removeClass('btn-default').addClass('btn-primary');
			// $(this).siblings('span').removeClass('btn-primary').addClass('btn-default');  // 删除其他兄弟元素的样式
		});

		$('.change_price').click(function () {
			var order_id = $(this).closest('tr').data('id');
			layer_font = layer.open({
				type: 2,
				title: '改价',
				shadeClose: true,
				shade: 0.8,
				area: ['70%', '90%'],
				content: '{:url("changePrice",'',false)}?order_id=' + order_id //iframe的url
			});
		});
		
		setTimeout(function(){
			window.location.reload(true);
		},120000);

		// function d(){
		// 	majax('{:url("remind")}',{},function(msg){
		// 		if(msg.code == 1){
		// 			document.getElementById('audio').play();
		// 		}
		// 	},{autoload:false,automsg:false});
		// }
		// d();
		// setInterval(d,60000);
	});

	function editSuccess(d) {
		layer.close(layer_font);
		layer.msg(d.msg, { icon: 1 }, function () {
			location.reload(true);
		});
	}

	$('.printcode').click(function(){
		var id = $(this).closest('tr').data('id');
		layer_font = layer.open({
          type: 2,
          title: '打印',
          shadeClose: true,
          shade: 0.8,
          area: ['900px', '90%'],
          content: '{:url("webPrintcode")}?order_id='+id, //iframe的url
        });
	})
	function closeIfram(){
	    layer.close(layer_font);
	}
	
	$(document).on('click','.excel',function(){
		$.each($('input:checkbox:checked'),function(){
			$this = $(this);
			$('.copy_excel').append($this.closest('tbody').clone());
		});
		exportTo();
	});
	
	function exportTo(type){
		$('.copy_excel').tableExport({
			filename: '%YY%-%MM%-%DD%',
			format: 'xls',
			cols: '3,4,5,6,7,8,9,10'
		});
	};
</script>